package com.mycompany.app.hr.eleave.model;

import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.apache.commons.lang.time.DurationFormatUtils;

import com.mycompany.app.hr.workflow.model.ApprovalStatus;

/**
 * Stands for Leave Transaction
 * 
 * @author Shawn.guo
 */
@Entity
@Table(name = "eleave_leave_application")
public class LeaveApplication {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "leave_application_id")
    private Long id;
    
    @Column(name = "applicant_gid")
    private String applicantGid;

    @Column(name="leave_type_id")
    private Long leaveTypeId;

    /** * approval workflow ** */
    @Embedded
    private ApprovalStatus approvalStatus=new ApprovalStatus();

    @OneToOne(mappedBy = "leaveApplication",fetch = FetchType.EAGER)
    private LeavePeriod period;

    // =======================================================
    @Override
    public String toString() {

        return ToStringBuilder.reflectionToString(this,
                ToStringStyle.SHORT_PREFIX_STYLE);
    }

    // =======================================================
    
    public Integer calculateCalendarDays() {

        return Integer.valueOf(DurationFormatUtils.formatPeriod(period
                .getFromDate().getTime(), period.getToDate().getTime(), "d"));

    }
    // =======================================================

    public Long getId() {

        return id;
    }

    public void setId(Long id) {

        this.id = id;
    }

    public String getApplicantGid() {

        return applicantGid;
    }

    public void setApplicantGid(String applicantGid) {

        this.applicantGid = applicantGid;
    }

    public ApprovalStatus getApprovalStatus() {

        return approvalStatus;
    }

    public void setApprovalStatus(ApprovalStatus approvalStatus) {

        this.approvalStatus = approvalStatus;
    }

    public LeavePeriod getPeriod() {

        return period;
    }

    public void setPeriod(LeavePeriod period) {

        this.period = period;
    }

    public Long getLeaveTypeId() {
    
        return leaveTypeId;
    }

    public void setLeaveTypeId(Long leaveTypeId) {
    
        this.leaveTypeId = leaveTypeId;
    }
    

}
